/*
 * @Author: your name
 * @Date: 2021-08-30 09:07:24
 * @LastEditTime: 2021-09-14 10:39:19
 * @LastEditors: Please set LastEditors
 * @Description: 维保团队列表数据
 * @FilePath: \weplus_weibao\src\consts\maintenanceteam\MaintenanceTeamConfig.js
 */
import Cookies from 'js-cookie';
import router from '@/router/index.js';
import { getCurrentInstance } from 'vue';

export default function maintenanceTeamTableCol () {
    const ctx = getCurrentInstance();
    const $st = ctx.appContext.config.globalProperties.$st;
    const sexMap = new Map([
        ['male', $st('Male')], ['female', $st('Female')]
    ]);
    const statusMap = new Map([
        ['0', $st('unknow')], ['1', $st('At_work')], ['2', $st('On_standby')], ['3', $st('Resting')]
    ]);
    // @ tableActions
    const clickNewMember = [];
    const username = Cookies.get('username');

    // @ tableProps
    const tableColsHeader = [{
        prop: 'account',
        label: $st('Account'),
        searchtype: 'text'
    }, {
        prop: 'alias',
        label: $st('Remark_name'),
        searchtype: 'text'
    }, {
        prop: 'sex',
        label: $st('Gender'),
        searchtype: 'filter',
        searchfilters: [{ label: $st('Male'), value: 'male' }, { label: $st('Female'), value: 'female' }]
    }, {
        prop: 'phone',
        label: $st('phone'),
        searchtype: 'text'
    }, {
        prop: 'customer_name',
        label: $st('Current_service_customer'),
        searchtype: 'filter',
        searchfilters: [{ label: 'test', value: 'test' }]
    }, {
        prop: 'address',
        label: $st('Invoice_recipient_address'),
        searchtype: 'text'
    }, {
        prop: 'status',
        label: $st('Status'),
        searchtype: 'filter',
        searchfilters: [{ label: $st('unknow'), value: '0' },
            { label: $st('At_work'), value: '1' },
            { label: $st('On_standby'), value: '2' },
            { label: $st('Resting'), value: '3' }]
    }];
    // @ tableRowActions
    const tableRowActions = [
        {
            label: $st('Check_in_record'),
            icon: 'roster',
            isdisable: (row) => { return !row.account && row.account !== username; },
            action: (row) => {
                for (var m of sexMap.entries()) {
                    if (m[1] === row.sex) {
                        row.sex = m[0];
                    }
                }
                for (var n of statusMap.entries()) {
                    if (n[1] === row.status) {
                        row.status = n[0];
                    }
                }
                router.push({
                    path: '/maintenanceTeam/detail',
                    query: { ...row, activeName: 'checkinRecords', labelName: $st('Check_in_record') }
                }).catch(() => {});
            }
        },
        {
            label: $st('Details'),
            icon: 'details',
            isdisable: (row) => { return !row.account && row.account !== username; },
            action: (row) => {
                for (var m of sexMap.entries()) {
                    if (m[1] === row.sex) {
                        row.sex = m[0];
                    }
                }
                for (var n of statusMap.entries()) {
                    if (n[1] === row.status) {
                        row.status = n[0];
                    }
                }
                router.push({
                    path: '/maintenanceTeam/detail',
                    query: { ...row, activeName: 'memberDetail', labelName: $st('Details') }
                }).catch(() => {});
            }
        },
        {
            label: $st('Withdraw'),
            icon: 'close',
            isdisable: (row) => { return !row.account && row.account !== username; },
            action: (row) => { alert(row.account); }
        }
    ];

    return {
        clickNewMember,
        tableColsHeader,
        tableRowActions
    };
}
